﻿/**********************************弘石项目*******************************************
* 功能描述: 系统设置  机构设置:人员 培训，常用设置
* 作者:石锦涛
* 时间:2021-12-21
* 
**********************************弘石项目*******************************************/
using HongStone.Domain.OperationsManagement;
using HongStone.Service;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using MiniExcelLibs;
using HongStone.Domain.AttendanceManagement;
using HongStone.Domain.SystemSetupModel.InstitutionSettingModel;
using HongStone.Dto;
using HongStone.Domain.SystemSetupModel.FrequentlyUsedDataModel;

namespace HongStone.API.Controllers
{

    [ApiExplorerSettings(GroupName = "SystemManagementSJT")]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SystemManagementSJTController : ControllerBase
    {
        private readonly SystemManagementSJTBll _systemManagementSJTBll;
        public SystemManagementSJTController(SystemManagementSJTBll systemManagementSJTBll)
        {
            _systemManagementSJTBll = systemManagementSJTBll;
        }

        /// <summary>
        /// 人员信息显示
        /// </summary>
        /// <param name="totalCount"></param>
        /// <param name="bum"></param>
        /// <param name="name"></param>
        /// <param name="state"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Showstaff( int? bum, string name, int? state, int pageindex = 1, int pagesize = 5)
        {
            try
            {
                var totalCount = 0;
                var list = _systemManagementSJTBll.Showstaff(out totalCount, bum, name, state, pageindex, pagesize);
                return Ok(new { totalCount,list});
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 人员信息添加
        /// </summary>
        /// <param name="staff"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddStaff(Staff staff)
        {
            try
            {
                return Ok(_systemManagementSJTBll.AddStaff(staff));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 上传 保存图片
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpLoad()
        {
            //http 协议 Request Response
            //获取文件
            var hpf = Request.Form.Files[0];
            //新名称
            var newFileName = Guid.NewGuid().ToString();
            //获取扩展名
            var ext = Path.GetExtension(hpf.FileName);
            //将文件名和扩展名拼接
            var newName = newFileName + ext;
            //找到路径  将虚拟路径转成物理路径
            var path = Directory.GetCurrentDirectory() + "/Images";
            //合并路径和文件名
            var newPath = Path.Combine(path, newName);

            using (var stream = System.IO.File.Create(newPath))
            {
                hpf.CopyTo(stream);

            }
            return Ok(new { url = newName });
        }


        /// <summary>
        /// 显示详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowstaffDetails(int id)
        {
            try
            {
                return Ok(_systemManagementSJTBll.ShowstaffDetails(id));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 人员信息修改
        /// </summary>
        /// <param name="staffst"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpdateStaff(Staff staffst)
        {
            try
            {
                return Ok(_systemManagementSJTBll.UpdateStaff(staffst));
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 人员批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult staffDate(string ids)
        {
            try
            {
                return Ok(_systemManagementSJTBll.staffDate(ids));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 培训信息列表
        /// </summary>
        /// <param name="bum"></param>
        /// <param name="xingzhi"></param>
        /// <param name="yeary"></param>
        /// <param name="month"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowTrains(int? bum, string xingzhi, int? yeary, string  month, string content)
        {
            try
            {
                return Ok(_systemManagementSJTBll.ShowTrains(bum, xingzhi, yeary, month, content));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 培训添加
        /// </summary>
        /// <param name="showTrainDto"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddTrains(ShowTrainDto showTrainDto)
        {
            try
            {

                return Ok(_systemManagementSJTBll.AddTrains(showTrainDto));
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 显示人员
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Showren(int? bum)
        {
            try
            {
                return Ok(_systemManagementSJTBll.Showren( bum));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 修改培训
        /// </summary>
        /// <param name="showTrainDto"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Updateshuju(ShowTrainDto showTrainDto)
        {

            try
            {
                return Ok(_systemManagementSJTBll.Updateshuju(showTrainDto));
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 删除培训
        /// </summary>
        /// <param name="TrainOneId"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Deteltesc(int TrainOneId)
        {
            try
            {
                return Ok(_systemManagementSJTBll.Deteltesc(TrainOneId));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 字典显示
        /// </summary>
        /// <returns></returns>

        [HttpGet]
        public IActionResult ShowDiction(string names, int pageindex = 1, int pagesize = 5)
        {
            try
            {
                var totalCount = 0;
                var list = _systemManagementSJTBll.ShowDiction(out totalCount, names, pageindex, pagesize);
                return Ok(new { totalCount, list});
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 字典添加
        /// </summary>
        /// <param name="dictionaries"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Diction(DictionariesTable dictionaries)
        {
            try
            {
                return Ok(_systemManagementSJTBll.Diction(dictionaries));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 字典修改
        /// </summary>
        /// <param name="dictionaries"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Update(DictionariesTable dictionaries)
        {
            try
            {
                return Ok(_systemManagementSJTBll.Update(dictionaries));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 字典 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult DeteleteDict(string ids)
        {
            try
            {
                return Ok(_systemManagementSJTBll.DeteleteDict(ids));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 链接显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowLink()
        {
            try
            {
                return Ok(_systemManagementSJTBll.ShowLink());
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 添加快捷链接
        /// </summary>
        /// <param name="fast"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddLinke(FastLink fast)
        {
            try
            {
                return Ok(_systemManagementSJTBll.AddLinke(fast));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 删除链接
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult DeleteLink(int id)
        {
            try
            {
                return Ok(_systemManagementSJTBll.DeleteLink(id));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 显示工资
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult staffwageshuju()
        {
            try
            {
                return Ok(_systemManagementSJTBll.staffwageshuju());
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        ///  导入 上传 Excel 工资
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Uploading()
        {
            try
            {
                var excel = this.HttpContext.Request.Form.Files[0];
                var stream = new MemoryStream();
                excel.CopyTo(stream);
                var list = stream.Query<StaffSalary>().ToList();
                return Ok(_systemManagementSJTBll.Uploading(list));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 显示职称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowPositions(string name)
        {
            try
            {
                return Ok(_systemManagementSJTBll.ShowPositions(name));
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 职称添加
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddPositions(PositionMessage position)
        {
            try
            {
                return Ok(_systemManagementSJTBll.AddPositions(position));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 修改职称数据
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpdatePositions(PositionMessage position)
        {
            try
            {
                return Ok(_systemManagementSJTBll.UpdatePositions(position));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 批量删除职称
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult DeletPositions(string ids)
        {
            try
            {
                return Ok(_systemManagementSJTBll.DeletPositions(ids));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 显示项目奖金统计
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowBonus()
        {
            try
            {
                return Ok(_systemManagementSJTBll.ShowBonus());
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 系数奖金修改
        /// </summary>
        /// <param name="bonus"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpdateBonus(List<BonusCoefficient> bonus)
        {
            try
            {
                return Ok(_systemManagementSJTBll.UpdateBonus(bonus));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 人员信息显示
        /// </summary>
        /// <param name="totalCount"></param>
        /// <param name="bum"></param>
        /// <param name="names"></param>
        /// <param name="yeays"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowRatkStaff(int? bum, string names, string yeays, int pageindex = 1, int pagesize = 10)
        {
            try
            {
                var totalCount = 0;
                var list = _systemManagementSJTBll.ShowRatkStaff(out totalCount, bum, names, yeays, pageindex, pagesize);
                return Ok(new { totalCount,list});

            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 显示级别
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowDictions()
        {
            try
            {
                return Ok(_systemManagementSJTBll.ShowDictions());
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 修改级别
        /// </summary>
        /// <param name="zhi"></param>
        /// <param name="jibie"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Updateshujib(int zhi, int jibie)
        {
            try
            {
                return Ok(_systemManagementSJTBll.Updateshujib(zhi, jibie));
            }
            catch (Exception)
            {

                throw;
            }
        }

    }
}
